package com.lb.jwitter.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;

import com.lb.jwitter.service.ConditionReport;
import com.lb.jwitter.service.TblCTDTDMNgayTrongTuan;
import com.lb.jwitter.service.TblCTDTDMNgayTrongTuanService;
import com.lb.jwitter.service.TblCTDTDMTietHocService;
import com.lb.jwitter.service.TblDKMHKetqua;
import com.lb.jwitter.service.TblDKMHLogKetQuaDangKy;
import com.lb.jwitter.service.TblDKMHLogKetQuaDangKyService;
import com.lb.jwitter.service.TblDKMHTaiKhoanHocVien;

import com.lb.jwitter.service.TblThongTinMonHoc;
import com.lb.jwitter.service.TblThongTinMonHocService;
import com.lb.jwitter.util.ApplicationContextProvider;
import com.lb.jwitter.util.KetQuaDangKy;
import com.lb.jwitter.util.ThoiKhoaBieuDuKien;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

@ContextConfiguration(locations="classpath:beans.xml") 
public class LichSuDangKyAction {

	private TblDKMHTaiKhoanHocVien tblDKMHTaiKhoanHocVien;
	public TblDKMHTaiKhoanHocVien getTblDKMHTaiKhoanHocVien() {
		return tblDKMHTaiKhoanHocVien;
	}

	public void setTblDKMHTaiKhoanHocVien(
			TblDKMHTaiKhoanHocVien tblDKMHTaiKhoanHocVien) {
		this.tblDKMHTaiKhoanHocVien = tblDKMHTaiKhoanHocVien;
	}


	private List<TblDKMHLogKetQuaDangKy> tblDKMHLogKetQuaDangKys ;
	public List<TblDKMHLogKetQuaDangKy> getTblDKMHLogKetQuaDangKys() {
		return tblDKMHLogKetQuaDangKys;
	}

	public void setTblDKMHLogKetQuaDangKys(
			List<TblDKMHLogKetQuaDangKy> tblDKMHLogKetQuaDangKys) {
		this.tblDKMHLogKetQuaDangKys = tblDKMHLogKetQuaDangKys;
	}

	private String code;
	private String msg;

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}


	@Autowired // Injected by Spring 
	ApplicationContextProvider contextProvider; 
	 	 
	public String execute() throws Exception
	{

		Map session = ActionContext.getContext().getSession();
		tblDKMHTaiKhoanHocVien =  (TblDKMHTaiKhoanHocVien) session.get("taiKhoanHocVien");
	     if( tblDKMHTaiKhoanHocVien == null) return "noprivilege";
	     
	     Integer dotDKId = (Integer) session.get("dotDKId");
	     
	    ApplicationContext context = contextProvider.getApplicationContext(); 
	    
	    TblDKMHLogKetQuaDangKyService tblDKMHLogKetQuaDangKyService = (TblDKMHLogKetQuaDangKyService) context.getBean("tbl_DKMH_LogKetQuaDangKyClient");
		if(dotDKId == null  ){
			code = "ERROR";
			msg = "bạn chưa chọn đợt đang ký!";
			return Action.ERROR;
			
		}
	    List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
	    { 
	        ConditionReport con = new ConditionReport(); 
	        con.setCol("dotDKId.id");
	        con.setValue1(new Long(dotDKId));
	        con.setOperator("eq");
	        cons.add(con);	
	    }
	    { 
	        ConditionReport con = new ConditionReport(); 
	        con.setCol("hocVienId.id");
	        con.setValue1(tblDKMHTaiKhoanHocVien.getHocVienId().getId());
	        con.setOperator("eq");
	        cons.add(con);	
	    }
	    { 
	        ConditionReport con = new ConditionReport(); 
	        con.setCol("ngayGhiLog");
	        con.setValue1("asc");
	        con.setOperator("order");
	        cons.add(con);	
	    }

	    
	    tblDKMHLogKetQuaDangKys = tblDKMHLogKetQuaDangKyService.findtblDKMHLogKetQuaDangKyByCondition(cons, 0, 0);
		return Action.SUCCESS;

	}


	
	
	
	
	
}
